package com.hns.tool.task.taque;

/**
 * 检查并中止执行超时的任务
 * @author:wucx
 * @email:zhuangcaijin@126.com
 * @version Revision 2.0.0
 */
public class TaskTerminator extends Thread{

	private Taque taque;
	
	TaskTerminator(Taque taque) {
		this.taque = taque;
		setDaemon(true);
	}
	
	/**
	 * 检查并中止执行超时的任务
	 * @email:zhuangcaijin@126.com
	 */
	public void run() {
		while(taque.isUp) {
			try {
				Thread.sleep(1000l);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			for(final Task task : taque.doings) {
				if ( task.isTimeout() ) {
					taque.execute(new TaskBreak(task));
				}
			}
		}
	}

}
